package com.dw.widget.slideshow.utils;

import com.dw.widget.slideshow.db.object.ImageData;

public class ImageDataCache {

	private ImageData[] imageCache = null;
	private int left = 0;   // 剩余数
	private int cursor = 0;  // 指针
	
	private static ImageDataCache _instance;
	
	public ImageDataCache()
	{
		
	}
	
	public static ImageDataCache Instance()
	{
		if(_instance == null)
		{
			_instance = new ImageDataCache();
		}
		
		return _instance;
	}
	
	public void setImageCache(ImageData[] imageCache) {
		this.imageCache = imageCache;
		cursor = 0;
		
		if(imageCache == null)
		{
			left = 0;
		}
		else
		{
			left = imageCache.length;
		}
	}
	public int getLeft() {
		return left;
	}
	
	public ImageData getNext()
	{
		if(imageCache == null || imageCache.length <= 0)
		{
			return null;
		}
		
		int total = imageCache.length;
		if(cursor >= total)
		{
			return imageCache[total - 1];
		}
		
		ImageData image = imageCache[cursor];
		cursor++;
		left--;
		
		return image;
	}
}
